<%@ page language="java" contentType="text/html;charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>部门用户管理</title>
		<link type="text/css" rel="stylesheet" href="../<s:property value="#session.themeStyle.mainCss" default="Skin/PM/LightBlue/main.css"/>" />
		<script type="text/javascript" src="<%=basePath %>js/jquery.js"></script>
		<script type="text/javascript" src="<%=basePath %>js/store.js"></script>
		<script type="text/javascript" src="<%=basePath %>js/modalWindow.js"></script>
		<style type="text/css">
		</style>
	</head>
	<script language="javascript">
		
		function addUser(){
			var deptId = $("#deptId").val();
			if(deptId==0){
				return false;
			}
			var url = "../userinfo/initAddUserInfo.action?deptId="+deptId;
//			var result=window.showModalDialog(url,'','resizable:no;scroll:yes;status:no;dialogWidth=550px;dialogHeight=230px;center=yes;help=no');
			showModalWindow(
					url,
					window,
					'resizable:no;scroll:yes;status:no;dialogWidth=550px;dialogHeight=230px;center=yes;help=no',
					saveUser
			);
		}
		
		function saveUser(result){
		   	if(result!=null&&result!='undefined'&&result!=''){
				var deptId = $("#deptId").val();
		   		var info = eval(result);
		   		var from = createFrom("../userinfo/addUserInfo.action");
		   		loadFrom("userName",info[0].userName,from);
		   		loadFrom("name",info[0].name,from);
		   		loadFrom("password",info[0].password,from);
		   		loadFrom("telphone",info[0].telphone,from);
		   		loadFrom("email",info[0].email,from);
		   		loadFrom("address",info[0].address,from);
		   		loadFrom("deptId",deptId,from);
		   		from.submit();
			}
		}
		
		function delUser(name, id){
			if (confirm("真的要删除用户 "+name+" 吗?")){
				$.ajax({
					url: "",
					type: "POST",
					dataType: "json",
					success: function(result){
						if (result.success){
							alert("用户已经删除");
							window.location.reload(true);
						}else{
							alert("用户删除失败："+result.errorMessage);
						}
					}
				});
			}
		}
		
		function editUser(id){
			var deptId = $("#deptId").val();
			var url = "../userinfo/userInfo-edit.action?pkId="+id;
//			var result=window.showModalDialog(url,'','resizable:no;scroll:yes;status:no;dialogWidth=550px;dialogHeight=230px;center=yes;help=no');
			showModalWindow(
					url,
					window,
					'resizable:no;scroll:yes;status:no;dialogWidth=550px;dialogHeight=230px;center=yes;help=no',
					updateUserComplate
			);
		}
		
		function updateUserComplate(result){
		   	if(result!=null&&result!='undefined'&&result!=''){
		   		if (result=="true"){
		   			window.location.reload(true);
		   		}
			}
		}

		function resetPassword(userId,userName){
			var tips = "你确定重置账号为（"+userName+"）的用户密码为：【8888】？";
			if(confirm(tips)){
//				window.location = "reStoreUserPWD.action?userId="+userId;
				$.ajax({
					url: "../userinfo/userInfo-resetPassword.action",
					type: "POST",
					data: {userId: userId},
					dataType: "json",
					success: function(result){
						if (result.success){
							alert("用户密码已经重置");
						}else{
							alert("用户密码重置失败："+result.errorMessage);
						}
					}
				});

			}
		}
		
	</script>
<body>
	<div class="tabBlock">
		<a class="but28" onclick="addUser()" style="text-decoration:none;margin-left: 5px;" >添加用户</a>&nbsp;&nbsp;<STRONG><s:property value="name"/></STRONG>&nbsp;&nbsp;成员列表：
		<div class="dataGrid" style="margin-top: 10px;">
				<table>
					<tr>
						<th nowrap="nowrap" width="15%">
							账号
						</th>
						<th nowrap="nowrap" width="15%">
							姓名
						</th>
						<th nowrap="nowrap" width="40%">
							所在部门
						</th>
						<th nowrap="nowrap" width="20%">
							操作
						</th>
					</tr>
					<s:if test="userList.size==0">
						<tr class="trStyle">
							<td colspan="4">
								(无)
							</td>
						</tr>
					</s:if>
					<s:iterator value="userList" status="st">
						<tr class="trStyle">
							<td>
								<s:property value="userName" />&nbsp;
							</td>
							<td>
								<s:property value="name" />&nbsp;
							</td>
							<td>
								<s:property value="userDept" />&nbsp;
							</td>
							<td>
								<a style="color: #e9621e;text-decoration: none;cursor: pointer;" onclick="delUser('<s:property value="name" />',<s:property value="pkId" />)">删除</a>
								<a style="color: #e9621e;text-decoration: none;cursor: pointer;" onclick="editUser(<s:property value="pkId" />)">修改</a>
								<a style="color: #e9621e;text-decoration: none;cursor: pointer;" onclick="resetPassword(<s:property value="pkId" />,'<s:property value="name" />')">重置密码</a>
							</td>
						</tr>
					</s:iterator>
				</table>
			</div>
	</div>
	<input type="hidden" id="deptId" value="<s:property value="deptId"/>" />
</body>
</html>